package com.xxx.course.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xxx.course.common.Result;
import com.xxx.course.entity.EduCourse;
import com.xxx.course.entity.EduVideo;
import com.xxx.course.entity.course.Video;
import com.xxx.course.service.EduCourseService;
import com.xxx.course.service.EduVideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 课程视频 前端控制器
 * </p>
 *
 * @author chn
 * @since 2022-05-30
 */
@RestController
@RequestMapping("/video")
@CrossOrigin
public class EduVideoController {
    @Autowired
    private EduVideoService eduVideoService;
    @GetMapping("/page/{current}/{limit}")
    public Result page(@PathVariable("current") long current, @PathVariable("limit") long limit){
        Page<EduVideo> page = new Page<>(current, limit);
        eduVideoService.page(page,null);
        return Result.ok().data("page",page);
    }
    @PostMapping("update")
    public Result update(@RequestBody EduVideo eduVideo){
        return eduVideoService.updateById(eduVideo)?Result.ok():Result.error();
    }
    @GetMapping("/get/{id}")
    public Result get(@PathVariable("id") String id){
        EduVideo video = eduVideoService.getById(id);
        return Result.ok().data("video",video);
    }
    @DeleteMapping("delete/{id}")
    public Result delete(@PathVariable("id") String id){
        return eduVideoService.removeById(id)?Result.ok():Result.error();
    }
    @PostMapping("add")
    public Result add(@RequestBody EduVideo video){
        return eduVideoService.save(video)?Result.ok():Result.error();
    }
}

